package utils

import (
	"server/global"

	"golang.org/x/crypto/bcrypt"
)

func GeneratePassword(password string) (string, error) {
	b, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
	if err != nil {
		global.GA_LOGGER.Sugar().Errorf("密码加密失败: %v", err)
		return "", err
	}
	return string(b), nil
}

func VerifyPasswordWithHashedPassword(hashedPassword, password string) bool {
	result := bcrypt.CompareHashAndPassword([]byte(hashedPassword), []byte(password))
	return result == nil
}
